<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>冒泡排序</title>
</head>
<body>

</body>
<script>

    /*
    * * 冒泡排序
    * */
    var arr = [2,90,34,390,45];
    /*
      *  2 90 34
      *   2  34 90 390 45
      *     2  34 90 45 390
    * */


      /*数值交换*/
    /*  var temp=arr[0];
       arr[0]=arr[1];
       arr[1]=temp;*/

      for(var j=0;j<arr.length;j++){
          for(var i=0;i<arr.length-1-j;i++){
              if(arr[i]>arr[i+1]){
                  var temp=arr[i];
                  arr[i]=arr[i+1];
                  arr[i+1]=temp;
              }

          }

      }

       console.log(arr);

</script>
</html>